package Day20;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo03 {
    public static void main(String[] args) {
        //定长线程池（长度指定）
        //1.判断线程池是否存在空闲线程
        //2.存在则使用
        //3.不存在空闲线程则判断线程池是否满了，不满则创建线程放入线程池然后使用
        //满了则等待
        ExecutorService service = Executors.newFixedThreadPool(2);
        service.execute(new Runnable(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "锄禾日当午");
            }
        });
        service.execute(new Runnable(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "锄禾日当午");
            }
        });
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        service.execute(new Runnable(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "锄禾日当午");
            }
        });
    }
}
